use serde::{Deserialize, Serialize};
use strum::{EnumMessage, EnumString};
#[derive(Debug, Clone, EnumMessage, EnumString, Serialize, Deserialize)]
pub enum UserStatus {
    #[strum(message = "激活")]
    Active,
    #[strum(message = "未激活")]
    Inactive,
    #[strum(message = "禁用")]
    Disabled,
}

#[cfg(test)]
mod tests {
    use std::str::FromStr;

    use serde::{Deserialize, Serialize};
    use strum::EnumMessage;

    use crate::UserStatus;

    #[derive(Debug, Serialize, Deserialize)]
    struct User {
        status: UserStatus,
    }

    #[test]
    fn test_user_status() {
        let status = UserStatus::Active;

        let user = User { status };

        let json = serde_json::to_string(&user).unwrap();
        println!("{}", json);

        let de_user = serde_json::from_str::<User>(&json).unwrap();
        println!("{:?}", de_user);
        println!("status: {:?}", de_user.status);
        println!("{:?}", de_user.status.get_message());

        let status = UserStatus::from_str("Disabled");
        println!("{:?}", status);
    }
}
